#include "stdafx.h"
#include "sasform.h"
#include "gearrenderhandler.h"

SASForm::SASForm(QWidget *parent)
    : QGLWidget(parent)
{
	renderHandler = NULL;
	renderHandler = new GearRenderHandler(this);

	QTimer *timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(slotPaintSAS()));
    timer->start(20);
}

SASForm::~SASForm()
{
}

void SASForm::initializeGL()
{
	if(renderHandler)
		renderHandler->initializeGL();
}

void SASForm::paintGL()
{		
    if(renderHandler)
	{
		if(!renderHandler->initialized())
			renderHandler->initializeGL();

		renderHandler->paintGL();
	}
}

void SASForm::resizeGL(int width, int height)
{
    if(renderHandler)
		renderHandler->resizeGL(width, height);
}

void SASForm::mousePressEvent(QMouseEvent *event)
{
    if(renderHandler)
		renderHandler->mousePressEvent(event);
}

void SASForm::mouseMoveEvent(QMouseEvent *event)
{
    if(renderHandler)
		renderHandler->mouseMoveEvent(event);
}

void SASForm::slotPaintSAS()
{
	if(isVisible())
	{
		if(renderHandler)
			renderHandler->renderLoop();
	}
}